import os
from tqdm import tqdm
import datetime
import random
from django.contrib.auth import get_user_model

if __name__ == '__main__':
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "izone.settings")
    import django

    django.setup()

    from django.db.models import Q
    from knowledge import models as knowledge_models

    # for i in range(0, 100):
    #     one = {
    #         "name": "BIM{}".format(i)
    #     }
    #     knowledge_models.Concept.objects.create(**one)

    res = knowledge_models.Concept.objects.all()
    print(res)

    # 创建文章标签
    # for i in range(0,100):
    #     one = {
    #         "name": "tag{}".format(i)
    #     }
    #     knowledge_models.Tag.objects.create(**one)

    res = knowledge_models.Tag.objects.all()
    print(res)

    # 创建文章
    # nums = [i for i in range(0, 100)]
    # for i in tqdm(range(0, 100)):
    #     one = {
    #         "title": "title{}".format(i),
    #     }
    #     knowledge_models.Article.objects.create(**one)
    #
    res = knowledge_models.Article.objects.all()
    print(res)

    t = knowledge_models.Article.objects.get(pk=1)
    print(t)

    # 创建文章标签对应
    # nums = [i for i in range(0, 100)]
    # for i in tqdm(range(1, 100)):
    #     r = random.randint(0, 99)
    #     article = knowledge_models.Article.objects.get(id=i)
    #     tag01 = knowledge_models.Tag.objects.get(pk=r)
    #     tag02 = knowledge_models.Tag.objects.get(pk=r + 1)
    #
    #     one = {
    #         "article": article,
    #         "tag": tag01,
    #     }
    #     knowledge_models.ArticleToTag.objects.create(**one)
    #
    #     two = {
    #         "article": article,
    #         "tag": tag02
    #     }
    #     knowledge_models.ArticleToTag.objects.create(**two)

    res = knowledge_models.ArticleToTag.objects.all()
    print(res)

    res = knowledge_models.ArticleToTag.get_articles_by_tag_pk(tag_pk=30)
    print(res)

    # 创建知识点
    # for i in tqdm(range(1, 99)):
    #     # article = knowledge_models.Article.objects.get(pk=i)
    #     concept01 = knowledge_models.Concept.objects.get(pk=i)
    #     concept02 = knowledge_models.Concept.objects.get(pk=i + 1)
    #
    #     knowledge_models.Point.objects.create(
    #         article_id=i,
    #         context="{}衍生出了{}".format(concept01.name, concept02.name),
    #         subject=concept01,
    #         object=concept02
    #     )
